﻿layui.use(['jquery','layer'], function () {
    var layer = layui.layer,
    $ = layui.jquery;
    //window.ValidateSession = function () {
    //    var rs = false;
    //    $.ajax({
    //        type: "post",
    //        cache: false,
    //        async: false,
    //        url: "/ashx/Common.ashx",
    //        data: {
    //            "op": "Session"
    //        },
    //        dataType: "json",
    //        success: function (rs) {
    //            rs = rs.State;
    //            if (rs.State) {
                    
    //            }
    //            else {
    //                layer.alert(rs.Msg, function (index) {
    //                    layer.close(index);
    //                    location = "//192.168.1.12";
    //                });
    //            }
    //        },
    //        error: function (error) {
    //            layer.msg(error.responseText);
    //        }
    //    });
    //    return rs;
    //}
    window.getWType = function () {
        var wtype;
        $.ajax({
            type: "post",
            cache: false,
            async: false,
            url: "/ashx/Common.ashx",
            data: {
                "op": "WType"
            },
            dataType: "json",
            success: function (rs) {
                wtype = rs;
            },
            error: function (error) {
                layer.msg(error.responseText);
            }
        });
        return wtype;
    }
    window.getLoginInfo=function() {
        var loginer;
        $.ajax({
            type: "post",
            cache: false,
            async: false,
            url: "/ashx/Common.ashx",
            data: {
                "op": "LoginInfo"
            },
            dataType: "json",
            success: function (rs) {
                if (rs.State) {
                    loginer = rs.Data1;
                }
            },
            error: function (error) {
                layer.msg(error.responseText);
            }
        });
        return loginer;
    }

    window.getZDList = function (all,split) {
        var list;
        $.ajax({
            type: "post",
            cache: false,
            async: false,
            url: "/ashx/Common.ashx",
            data: {
                "op": "ZDList",
                "split": split,
                "all":all
            },
            dataType: "json",
            success: function (rs) {
                if (rs.State) {
                    list = rs.Data1;
                }
            },
            error: function (error) {
                layer.msg(error.responseText);
            }
        });
        return list;
    }

    window.getGLKList = function (all, split) {
        var list;
        $.ajax({
            type: "post",
            cache: false,
            async: false,
            url: "/ashx/Common.ashx",
            data: {
                "op": "GLKList",
                "split": split,
                "all": all
            },
            dataType: "json",
            success: function (rs) {
                if (rs.State) {
                    list = rs.Data1;
                }
            },
            error: function (error) {
                layer.msg(error.responseText);
            }
        });
        return list;
    }

    window.getQSBMList = function (split) {
        var list;
        $.ajax({
            type: "post",
            cache: false,
            async: false,
            url: "/ashx/Common.ashx",
            data: {
                "op": "QSBMList",
                "split": split
            },
            dataType: "json",
            success: function (rs) {
                if (rs.State) {
                    list = rs.Data1;
                }
            },
            error: function (error) {
                layer.msg(error.responseText);
            }
        });
        return list;
    }

    window.getYSBMList = function (split) {
        var list;
        $.ajax({
            type: "post",
            cache: false,
            async: false,
            url: "/ashx/Common.ashx",
            data: {
                "op": "YSBMList",
                "split": split
            },
            dataType: "json",
            success: function (rs) {
                if (rs.State) {
                    list = rs.Data1;
                }
            },
            error: function (error) {
                layer.msg(error.responseText);
            }
        });
        return list;
    }

    window.getFaPiaoHM=function(count) {
        var fphms = "";
        //显示当前打印发票号码
        $.ajax({
            type: "post",
            cache: false,
            async: false,
            url: "/ashx/YSZW/FaPiao.ashx",
            data: {
                "op": "FiaoPiaoHMHQ",
                "count": count
            },
            dataType: "json",
            success: function (rs) {
                if (rs.State) {
                    fphms = rs.Data1;
                }
                else {
                    if (rs.Data1 == "session") {
                        layer.alert(rs.Msg, function (index) {
                            layer.close(index);
                            location = "//192.168.1.12";
                        });
                    }
                    else {
                        layer.alert(rs.Msg);
                    }
                }
            },
            error: function (error) {
                layer.msg(error.responseText);
            }
        });
        return fphms;
    }
    //打开或关闭遮罩层
    //on true:打开遮罩 false:关闭
    //divid:要遮罩的div ID
    window.listCover=function(on, divid) {
        if (on) {
            $("#" + divid).after("<div id='divListCover'></div>");
            $("#divListCover").css({
                'opacity': 0.1,
                'position': 'absolute',
                'top': $("#" + divid).offset().top,
                'left': $("#" + divid).offset().left,
                'background-color': '#AAAAAA',
                'width': $("#" + divid).width(),
                'height': $("#" + divid).height(),
                'z-index': 5000
            });
        }
        else {
            $("#divListCover").remove();
        }
    }
    //循环处理数组,避免假死
    window.chunk=function(array, process, cbfun) {
        var index = layer.load(1);
        var i = 0, len = array.length;    //这里要注意在执行过程中数组最好是不变的
        setTimeout(function () {
            process(array[i], i++);    //循环体要做的操作
            if (i < len) {
                setTimeout(arguments.callee, 1);
            }
            else {//循环结束之后要做的操作
                if (cbfun != null) {
                    cbfun();
                }
                layer.close(index);
            }
        })
    }
});